package com.atguigu.service.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.dao.MemberDao;
import com.atguigu.pojo.Member;
import com.atguigu.service.MemberService;
import com.atguigu.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService{
    @Autowired
    private MemberDao memberDao;

    @Override
    public Member findMemberByTelehone(String telephone) {
        return memberDao.findMemberByTelephone(telephone);
    }

    @Override
    public void save(Member member) {
        memberDao.save(member);
    }
    // 根据月份统计会员数量

    @Override
    public Map<String, Object> getMemberReport(List<String> paramList) {
        List<Integer> memberCount = new ArrayList<Integer>();
        //循环调用12次
        for (String monthStr : paramList) {
            int countMonth = memberDao.getMemberCountByMonth(monthStr);
            memberCount.add(countMonth);
        }
        Map map = new HashMap<>();
        map.put("months", paramList);
        map.put("memberCount", memberCount);
        return map;
    }
}
